
 



 
 
 



 
 
 <!DOCTYPE html>
<html>
<head>
 <link rel="icon" type="image/vnd.microsoft.icon" href="http://www.gstatic.com/codesite/ph/images/phosting.ico">
 
 
 <link rel="canonical" href="http://code.google.com/p/httplib2/wiki/Examples" />
 
 <script type="text/javascript">
 
 
 
 
 var codesite_token = "iElak6eun-HcxTQFldHga11rLTw:1325929438858";
 
 
 var CS_env = {"profileUrl":["/u/104752254533010251311/"],"token":"iElak6eun-HcxTQFldHga11rLTw:1325929438858","assetHostPath":"http://www.gstatic.com/codesite/ph","domainName":null,"assetVersionPath":"http://www.gstatic.com/codesite/ph/1847340689237817661","projectHomeUrl":"/p/httplib2","relativeBaseUrl":"","projectName":"httplib2","loggedInUserEmail":"LuoC.gucas@gmail.com"};
 var _gaq = _gaq || [];
 _gaq.push(
 ['siteTracker._setAccount', 'UA-18071-1'],
 ['siteTracker._trackPageview']);
 
 _gaq.push(
 ['projectTracker._setAccount', 'UA-1974123-5'],
 ['projectTracker._trackPageview']);
 
 
 </script>
 
 
 <title>Examples - 
 httplib2 -
 
 Examples of how to use httplib2 - 
 A comprehensive HTTP client library in Python - Google Project Hosting
 </title>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" >
 
 <meta name="ROBOTS" content="NOARCHIVE">
 
 <link type="text/css" rel="stylesheet" href="http://www.gstatic.com/codesite/ph/1847340689237817661/css/core.css">
 
 <link type="text/css" rel="stylesheet" href="http://www.gstatic.com/codesite/ph/1847340689237817661/css/ph_detail.css" >
 
 
 
 <link type="application/atom+xml" rel="alternate" href="/feeds/p/httplib2/hgchanges/basic?repo=wiki&amp;path=/Examples.wiki">
 
 
<!--[if IE]>
 <link type="text/css" rel="stylesheet" href="http://www.gstatic.com/codesite/ph/1847340689237817661/css/d_ie.css" >
<![endif]-->
 <style type="text/css">
 .menuIcon.off { background: no-repeat url(http://www.gstatic.com/codesite/ph/images/dropdown_sprite.gif) 0 -42px }
 .menuIcon.on { background: no-repeat url(http://www.gstatic.com/codesite/ph/images/dropdown_sprite.gif) 0 -28px }
 .menuIcon.down { background: no-repeat url(http://www.gstatic.com/codesite/ph/images/dropdown_sprite.gif) 0 0; }
 
 
 #maincol {
 padding-top: 0;
 padding-bottom: 0;
 }

 
 </style>
</head>
<body class="t6">
<script type="text/javascript">
 (function() {
 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
 (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
 })();
</script>
<div class="headbg">

 <div id="gaia">
 

 <span>
 
 
 <a href="#" id="multilogin-dropdown" onclick="return false;"
 ><u><b>LuoC.gucas@gmail.com</b></u> <small>&#9660;</small></a>
 
 
 | <a href="/u/104752254533010251311/" id="projects-dropdown" onclick="return false;"
 ><u>My favorites</u> <small>&#9660;</small></a>
 | <a href="/u/104752254533010251311/" onclick="_CS_click('/gb/ph/profile');"
 title="Profile, Updates, and Settings"
 ><u>Profile</u></a>
 | <a href="https://www.google.com/accounts/Logout?continue=http%3A%2F%2Fcode.google.com%2Fp%2Fhttplib2%2Fwiki%2FExamples" 
 onclick="_CS_click('/gb/ph/signout');"
 ><u>Sign out</u></a>
 
 </span>

 </div>

 <div class="gbh" style="left: 0pt;"></div>
 <div class="gbh" style="right: 0pt;"></div>
 
 
 <div style="height: 1px"></div>
<!--[if lte IE 7]>
<div style="text-align:center;">
Your version of Internet Explorer is not supported. Try a browser that
contributes to open source, such as <a href="http://www.firefox.com">Firefox</a>,
<a href="http://www.google.com/chrome">Google Chrome</a>, or
<a href="http://code.google.com/chrome/chromeframe/">Google Chrome Frame</a>.
</div>
<![endif]-->




 <table style="padding:0px; margin: 0px 0px 10px 0px; width:100%" cellpadding="0" cellspacing="0"
 itemscope itemtype="http://schema.org/CreativeWork">
 <tr style="height: 58px;">
 
 <td id="plogo">
 <link itemprop="url" href="/p/httplib2">
 <a href="/p/httplib2/">
 
 <img src="http://www.gstatic.com/codesite/ph/images/defaultlogo.png" alt="Logo" itemprop="image">
 
 </a>
 </td>
 
 <td style="padding-left: 0.5em">
 
 <div id="pname">
 <a href="/p/httplib2/"><span itemprop="name">httplib2</span></a>
 </div>
 
 <div id="psum">
 <a id="project_summary_link"
 href="/p/httplib2/"><span itemprop="description">A comprehensive HTTP client library in Python</span></a>
 
 </div>
 
 
 </td>
 <td style="white-space:nowrap;text-align:right; vertical-align:bottom;">
 
 <form action="/hosting/search">
 <input size="30" name="q" value="" type="text">
 
 <input type="submit" name="projectsearch" value="Search projects" >
 </form>
 
 </tr>
 </table>

</div>

 
<div id="mt" class="gtb"> 
 <a href="/p/httplib2/" class="tab ">Project&nbsp;Home</a>
 
 
 
 
 <a href="/p/httplib2/downloads/list" class="tab ">Downloads</a>
 
 
 
 
 
 <a href="/p/httplib2/w/list" class="tab active">Wiki</a>
 
 
 
 
 
 <a href="/p/httplib2/issues/list"
 class="tab ">Issues</a>
 
 
 
 
 
 <a href="/p/httplib2/source/checkout"
 class="tab ">Source</a>
 
 
 
 
 
 <div class=gtbc></div>
</div>
<table cellspacing="0" cellpadding="0" width="100%" align="center" border="0" class="st">
 <tr>
 
 
 
 <td class="subt">
 <div class="issueDetail">
<div class="isf">
 
 <span class="inIssueList"> 
 <span>Search</span>
 <form action="/p/httplib2/w/list" method="GET" style="display:inline">
 <select id="can" name="can" >
 <option disabled="disabled">Search within:</option>
 
 <option value="1" >&nbsp;All wiki pages</option>
 <option value="3" >&nbsp;Featured pages</option>
 <option value="2" selected="selected">&nbsp;Current pages</option>
 
 
 <option value="5" >&nbsp;My starred pages</option>
 
 <option value="4" >&nbsp;Deprecated pages</option>
 
 </select>
 <span>for</span>
 <span id="qq"><input type="text" size="38" id="searchq" name="q" value=""
 autocomplete="off" ></span>
 
 
 
 <input type="submit" value="Search" >
 </form>
 </span>

 
 
 
 
 
 
 

</div>
</div>

 </td>
 
 
 
 
 
 
 <td align="right" valign="top" class="bevel-right"></td>
 </tr>
</table>


<script type="text/javascript">
 var cancelBubble = false;
 function _go(url) { document.location = url; }
</script>
<div id="maincol"
 
>

 
<!-- IE -->







 <style type="text/css">
 .delcom { background: #e8e8e8 }
 .commentcontent {
 margin: 2em;
 padding: 0px 10px;
 width: 66em;
 }
 .artifactcomment {
 border-top: 3px solid #c3d9ff;
 }
 #commentform {
 border-top: 3px solid #c3d9ff;
 }
 </style>

<div id="wikipage">
<table>
 <tr>
 
 
 <td style="vertical-align:top; padding-left:5px">
 
 <div id="wikiheader">
 
 <img width="15" height="15" id="star_img"
 src="http://www.gstatic.com/codesite/ph/images/star_off.gif"
 style="cursor:pointer"
 onclick="_CS_toggleStar(this,
 {'scope': 'wiki',
 'user': '_CURRENT_USER',
 'item': 'httplib2:Examples'
 });"/>
 
 <span style="font-size:120%;font-weight:bold">Examples</span>
 &nbsp;
 <div> 
 
 <i>Examples of how to use httplib2</i>
 
 
 <br/>
 
 <a class="label" style="padding-top: 2px"
 href="/p/httplib2/w/list?q=label:Featured"
 title="Listed on project home page"
 >Featured</a>
 
 
 
 <div id="wikiauthor" style="float:right">
 Updated <span title="Mon Jul 13 11:26:01 2009">
 Jul 13, 2009</span>
 
 by <a style="white-space: nowrap" href="/u/111966606387715428604/">pilg...@gmail.com</a>
 
 </div>
 </div>
 </div>
 
 <div id="wikicontent">
 <div class="vt" id="wikimaincol">
 <h3><a name="Simple_Retrieval"></a>Simple Retrieval<a href="#Simple_Retrieval" class="section_anchor"></a></h3><pre class="prettyprint">import httplib2
h = httplib2.Http(&quot;.cache&quot;)
resp, content = h.request(&quot;http://example.org/&quot;, &quot;GET&quot;)</pre><p>The &#x27;content&#x27; is the content retrieved from the URL. The content is already decompressed or unzipped if necessary. The &#x27;resp&#x27; contains all the response headers. </p><h3><a name="Authentication"></a>Authentication<a href="#Authentication" class="section_anchor"></a></h3><p>To PUT some content to a server that uses SSL and Basic authentication: </p><pre class="prettyprint">import httplib2
h = httplib2.Http(&quot;.cache&quot;)
h.add_credentials(&#x27;name&#x27;, &#x27;password&#x27;)
resp, content = h.request(&quot;https://example.org/chap/2&quot;, 
    &quot;PUT&quot;, body=&quot;This is text&quot;, 
    headers={&#x27;content-type&#x27;:&#x27;text/plain&#x27;} )</pre><h3><a name="Cache-Control"></a>Cache-Control<a href="#Cache-Control" class="section_anchor"></a></h3><p>Use the <tt>Cache-Control:</tt> header to control how the caching operates. </p><pre class="prettyprint">import httplib2
h = httplib2.Http(&quot;.cache&quot;)
resp, content = h.request(&quot;http://bitworking.org/&quot;)
 ...
resp, content = h.request(&quot;http://bitworking.org/&quot;, 
    headers={&#x27;cache-control&#x27;:&#x27;no-cache&#x27;})</pre><p>The first request will be cached and since this is a request to bitworking.org it will be set to be cached for two hours, because that is how I have my server configured. Any subsequent GET to that URI will return the value from the on-disk cache and no request will be made to the server. You can use the <tt>Cache-Control:</tt> header to change the caches behavior and in this example the second request adds the <tt>Cache-Control:</tt> header with a value of &#x27;no-cache&#x27; which tells the library that the cached copy must not be used when handling this request.  </p><h3><a name="Forms"></a>Forms<a href="#Forms" class="section_anchor"></a></h3><p>Below is an example of using <tt>httplib2</tt> to submit a form. Note that we have to use the <tt>urlencode()</tt> function from <tt>urllib</tt> to encode the data before using it as the POST body. </p><pre class="prettyprint">&gt;&gt;&gt; from httplib2 import Http
&gt;&gt;&gt; from urllib import urlencode
&gt;&gt;&gt; h = Http()
&gt;&gt;&gt; data = dict(name=&quot;Joe&quot;, comment=&quot;A test comment&quot;)
&gt;&gt;&gt; resp, content = h.request(&quot;http://bitworking.org/news/223/Meet-Ares&quot;, &quot;POST&quot;, urlencode(data))
&gt;&gt;&gt; resp
{&#x27;status&#x27;: &#x27;200&#x27;, &#x27;transfer-encoding&#x27;: &#x27;chunked&#x27;, &#x27;vary&#x27;: &#x27;Accept-Encoding,User-Agent&#x27;,
 &#x27;server&#x27;: &#x27;Apache&#x27;, &#x27;connection&#x27;: &#x27;close&#x27;, &#x27;date&#x27;: &#x27;Tue, 31 Jul 2007 15:29:52 GMT&#x27;, 
 &#x27;content-type&#x27;: &#x27;text/html&#x27;}</pre><h3><a name="Cookies"></a>Cookies<a href="#Cookies" class="section_anchor"></a></h3><p>When automating something, you often need to &quot;login&quot; to maintain some sort of session/state with the server.  Sometimes this is achieved with form-based authentication and cookies. You post a form to the server, and it responds with a cookie in the incoming HTTP header.  You need to pass this cookie back to the server in subsequent requests to maintain state or to keep a session alive. </p><p>Here is an example of how to deal with cookies when doing your HTTP Post. </p><p>First, lets import the modules we will use: </p><pre class="prettyprint">import urllib
import httplib2</pre><p>Now, lets define the data we will need. In this case, we are doing a form post with 2 fields representing a username and a password. </p><pre class="prettyprint">url = &#x27;http://www.example.com/login&#x27;   
body = {&#x27;USERNAME&#x27;: &#x27;foo&#x27;, &#x27;PASSWORD&#x27;: &#x27;bar&#x27;}
headers = {&#x27;Content-type&#x27;: &#x27;application/x-www-form-urlencoded&#x27;}</pre><p>Now we can send the HTTP request: </p><pre class="prettyprint">http = httplib2.Http()
response, content = http.request(url, &#x27;POST&#x27;, headers=headers, body=urllib.urlencode(body))</pre><p>At this point, our &quot;response&quot; variable contains a dictionary of HTTP header fields that were returned by the server. If a cookie was returned, you would see a &quot;set-cookie&quot; field containing the cookie value. We want to take this value and put it into the outgoing HTTP header for our subsequent requests: </p><pre class="prettyprint">headers[&#x27;Cookie&#x27;] = response[&#x27;set-cookie&#x27;]</pre><p>Now we can send a request using this header and it will contain the cookie, so the server can recognize us. </p><p>So... here is the whole thing in a script. We login to a site and then make another request using the cookie we received: </p><pre class="prettyprint">#!/usr/bin/env python

import urllib
import httplib2

http = httplib2.Http()

url = &#x27;http://www.example.com/login&#x27;   
body = {&#x27;USERNAME&#x27;: &#x27;foo&#x27;, &#x27;PASSWORD&#x27;: &#x27;bar&#x27;}
headers = {&#x27;Content-type&#x27;: &#x27;application/x-www-form-urlencoded&#x27;}
response, content = http.request(url, &#x27;POST&#x27;, headers=headers, body=urllib.urlencode(body))

headers = {&#x27;Cookie&#x27;: response[&#x27;set-cookie&#x27;]}

url = &#x27;http://www.example.com/home&#x27;   
response, content = http.request(url, &#x27;GET&#x27;, headers=headers)</pre><h3><a name="Proxies"></a>Proxies<a href="#Proxies" class="section_anchor"></a></h3><p><tt>httplib2</tt> can use a SOCKS proxy if the third-party <a href="http://socksipy.sourceforge.net/" rel="nofollow">socks</a> module is installed. </p><p>Here is an example of how to use the proxy support: </p><pre class="prettyprint">import httplib2
import socks

httplib2.debuglevel=4
h = httplib2.Http(proxy_info = httplib2.ProxyInfo(socks.PROXY_TYPE_HTTP, &#x27;localhost&#x27;, 8000))
r,c = h.request(&quot;http://bitworking.org/news/&quot;)</pre>
 </div>
 </div>
 </td><tr>
</table>
 </div>


 
 <div id="wikicommentcol">
 


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

<div class="collapse">


 


<div id="commentlist">

 
 <div class="artifactcomment"
 
 >
 
 
 
 
 
 
 <span class="author">Comment
 
 by 
 
 <a style="white-space: nowrap" href="/u/103274885532288727180/">chris.le...@gmail.com</a>,
 
 </span>
 <span class="date" title="Fri Dec 14 20:18:09 2007">Dec 14, 2007</span>
 <div>
<div class="commentcontent">
<p>Thank you for a great library. </p>
</div>
 
 
 </div>
 </div>
 

 
 <div class="artifactcomment"
 
 >
 
 
 
 
 
 
 <span class="author">Comment
 
 by 
 
 <a style="white-space: nowrap" href="/u/110975532720171676672/">cleanscr...@gmail.com</a>,
 
 </span>
 <span class="date" title="Wed Mar 26 23:42:07 2008">Mar 26, 2008</span>
 <div>
<div class="commentcontent">
<p>Nice :) I&#x27;m loving it :P </p>
</div>
 
 
 </div>
 </div>
 

 
 <div class="artifactcomment"
 
 >
 
 
 
 
 
 
 <span class="author">Comment
 
 by 
 
 <a style="white-space: nowrap" href="/u/110602018347372040860/">simonwil...@gmail.com</a>,
 
 </span>
 <span class="date" title="Tue Apr  8 05:52:08 2008">Apr 8, 2008</span>
 <div>
<div class="commentcontent">
<p>Manually handling cookies seems a bit backward; it would be nice if there was a flag to tell an Http() instance to automatically store and repeat any cookies during the session. </p>
</div>
 
 
 </div>
 </div>
 

 
 <div class="artifactcomment"
 
 >
 
 
 
 
 
 
 <span class="author">Comment
 
 by 
 
 <a style="white-space: nowrap" href="/u/110602018347372040860/">simonwil...@gmail.com</a>,
 
 </span>
 <span class="date" title="Wed May 21 04:42:37 2008">May 21, 2008</span>
 <div>
<div class="commentcontent">
<p>The proxy example uses a module called &quot;socks&quot;. I eventually tracked that down to here: </p><p><a href="http://code.creativecommons.org/svnroot/stats/socks.py" rel="nofollow">http://code.creativecommons.org/svnroot/stats/socks.py</a> </p><p>The magic socks.PROXY_TYPE_HTTP constant is &quot;3&quot;. </p>
</div>
 
 
 </div>
 </div>
 

 
 <div class="artifactcomment"
 
 >
 
 
 
 
 
 
 <span class="author">Comment
 
 by 
 
 <a style="white-space: nowrap" href="/u/105462080312452767923/">scott.jo...@gmail.com</a>,
 
 </span>
 <span class="date" title="Tue Aug 26 13:03:12 2008">Aug 26, 2008</span>
 <div>
<div class="commentcontent">
<p>It looks like the home of socks.py is here: <a href="http://socksipy.sourceforge.net/" rel="nofollow">http://socksipy.sourceforge.net/</a> </p>
</div>
 
 
 </div>
 </div>
 

 
 <div class="artifactcomment"
 
 >
 
 
 
 
 
 
 <span class="author">Comment
 
 by 
 
 <a style="white-space: nowrap" href="/u/111084531624358318565/">gal...@gmail.com</a>,
 
 </span>
 <span class="date" title="Fri Dec  5 07:55:51 2008">Dec 5, 2008</span>
 <div>
<div class="commentcontent">
<p>Note about timeouts, in case this helps anyone... </p><p>Each Http object you create maintains an open connection for every server you connect to (this is sensible as it reduces overhead for multiple requests). </p><p>However, it means that, when testing, it&#x27;s no good pausing between requests - the open http connections will timeout (the remote server will close them). httplib2 makes no effort to create a new connection in this case - you&#x27;ll just get an error message. </p><p>This is pretty confusing if you weren&#x27;t expecting that behaviour, and it isn&#x27;t obvious from the examples. So, create a new Http object whenever your old one might have timed out; don&#x27;t re-use an old one that&#x27;s been left for more than a few seconds. </p>
</div>
 
 
 </div>
 </div>
 

 
 <div class="artifactcomment"
 
 >
 
 
 
 
 
 
 <span class="author">Comment
 
 by 
 
 <a style="white-space: nowrap" href="/u/marc.boeker/">marc.boeker</a>,
 
 </span>
 <span class="date" title="Thu Mar 26 03:47:12 2009">Mar 26, 2009</span>
 <div>
<div class="commentcontent">
<p>great piece of code. i love the simplicity and the power. keep it up! </p>
</div>
 
 
 </div>
 </div>
 

 
 <div class="artifactcomment"
 
 >
 
 
 
 
 
 
 <span class="author">Comment
 
 by 
 
 <a style="white-space: nowrap" href="/u/113300528040213634655/">erik...@hotmail.com</a>,
 
 </span>
 <span class="date" title="Tue Jun 23 15:38:03 2009">Jun 23, 2009</span>
 <div>
<div class="commentcontent">
<p>Compatibility problem with Python 2.6: httplib.HTTPConnection and httplib.HTTPSConnection now support a timeout parameter to their constructors, which they store in self.timeout. This conflicts with the httplib2.HTTPConnectionWithTimeout and httplib2.HTTPSConnectionWithTimeout use of self.timeout, resulting in the following error:  </p><pre class="prettyprint">File &quot;...httplib2\__init__.py&quot;, line 736, in connect 
    sock.settimeout(self.timeout) 
  File &quot;&lt;string&gt;&quot;, line 1, in settimeout 
TypeError: a float is required</pre><p>To rectify this, add the following code near the top of httplib2\init.py:  </p><pre class="prettyprint"># Python 2.6 support
python26OrHigher = (sys.version_info &gt;= (2,6)) </pre><p>Then modify HTTPConnectionWithTimeout.init(): </p><pre class="prettyprint">        # Modified from original httplib2 source: HTTPConnection supports timeouts in Python 2.6.
        if python26OrHigher: 
            httplib.HTTPConnection.init(self, host, port, strict, timeout=timeout)
        else:
            httplib.HTTPConnection.init(self, host, port, strict) self.timeout = timeout </pre><p>HTTPConnectionWithTimeout.connect() change:  </p><pre class="prettyprint">        # Modified from original httplib2 source: HTTPConnection supports timeouts in Python 2.6.
        if not python26OrHigher: 
            if self.timeout is not None: 
                self.sock.settimeout(self.timeout) </pre><p>Similar for HTTPSConnectionWithTimeout.init():  </p><pre class="prettyprint">        # Modified from original httplib2 source: HTTPSConnection supports timeouts in Python 2.6.
        if python26OrHigher: 
            httplib.HTTPSConnection.init(self, host, port=port, key_file=key_file, cert_file=cert_file, strict=strict, timeout=timeout) 
        else: 
            httplib.HTTPSConnection.init(self, host, port=port, key_file=key_file, cert_file=cert_file, strict=strict)
            self.timeout = timeout</pre><p>And connect():  </p><pre class="prettyprint">        # Modified from original httplib2 source: HTTPSConnection supports timeouts in Python 2.6. 
        if not python26OrHigher: 
            if self.timeout is not None: 
                sock.settimeout(self.timeout)</pre>
</div>
 
 
 </div>
 </div>
 

 
 <div class="artifactcomment"
 
 >
 
 
 
 
 
 
 <span class="author">Comment
 
 by 
 
 <a style="white-space: nowrap" href="/u/117060974348302572416/">davidld...@gmail.com</a>,
 
 </span>
 <span class="date" title="Thu Jun 25 17:14:11 2009">Jun 25, 2009</span>
 <div>
<div class="commentcontent">
<p>has the above change made it into the repo? </p>
</div>
 
 
 </div>
 </div>
 

 
 <div class="artifactcomment"
 
 >
 
 
 
 
 
 
 <span class="author">Comment
 
 by 
 
 <a style="white-space: nowrap" href="/u/112980851258267732682/">garry.be...@gmail.com</a>,
 
 </span>
 <span class="date" title="Fri Jul 10 07:58:38 2009">Jul 10, 2009</span>
 <div>
<div class="commentcontent">
<p>Any estimate to when this is going to have the the changes above made?  It&#x27;s broken in 2.6 without it. </p>
</div>
 
 
 </div>
 </div>
 

 
 <div class="artifactcomment"
 
 >
 
 
 
 
 
 
 <span class="author">Comment
 
 by  project member 
 
 <a style="white-space: nowrap" href="/u/joe.gregorio/">joe.gregorio</a>,
 
 </span>
 <span class="date" title="Mon Jul 13 10:25:46 2009">Jul 13, 2009</span>
 <div>
<div class="commentcontent">
<p>I&#x27;m starting work on a 0.5 release now and fixes for this will be incorporated. </p>
</div>
 
 
 </div>
 </div>
 

 
 <div class="artifactcomment"
 
 >
 
 
 
 
 
 
 <span class="author">Comment
 
 by 
 
 <a style="white-space: nowrap" href="/u/107177939083429428284/">miser...@gmail.com</a>,
 
 </span>
 <span class="date" title="Tue Oct 27 22:08:56 2009">Oct 27, 2009</span>
 <div>
<div class="commentcontent">
<p>I would really like to see an example of an HTTPS connection with certificate supplied over a SOCKS5 proxy. </p><pre class="prettyprint">                h = httplib2.Http(proxy_info = httplib2.ProxyInfo(socks.PROXY_TYPE_SOCKS5, self.px_url, self.proxy_port))
                h.add_certificate(self.certificate.ikeyfile, self.certificate.certfile, self.url)
                resp, content = h.request(&quot;https://&quot;+self.url+&quot;:&quot;+str(self.remote_port)+self.path+query)</pre><p>This gives me a (8, &#x27;EOF occurred in violation of protocol&#x27;) error. </p><p>Got all the imports..but am I going about this wrong? Or is it impossible.. </p>
</div>
 
 
 </div>
 </div>
 

 
 <div class="artifactcomment"
 
 >
 
 
 
 
 
 
 <span class="author">Comment
 
 by 
 
 <a style="white-space: nowrap" href="/u/107451133287151117999/">stu.a...@gmail.com</a>,
 
 </span>
 <span class="date" title="Wed Feb 10 19:03:43 2010">Feb 10, 2010</span>
 <div>
<div class="commentcontent">
<p>Is there a way to return the content of a URL only if it&#x27;s in the cache ? </p>
</div>
 
 
 </div>
 </div>
 

 
 <div class="artifactcomment"
 
 >
 
 
 
 
 
 
 <span class="author">Comment
 
 by 
 
 <a style="white-space: nowrap" href="/u/108345598141141979059/">bjou...@gmail.com</a>,
 
 </span>
 <span class="date" title="Sun Apr  4 15:47:39 2010">Apr 4, 2010</span>
 <div>
<div class="commentcontent">
<p>Probably you should mention that you always should set the {&#x27;Content-type&#x27;: &#x27;application/x-www-form-urlencoded&#x27;} header when using POST. The header is not set automatically as it is with urllib for example. </p>
</div>
 
 
 </div>
 </div>
 

 
 <div class="artifactcomment"
 
 >
 
 
 
 
 
 
 <span class="author">Comment
 
 by 
 
 <a style="white-space: nowrap" href="/u/112794373709407819976/">edgardo....@gmail.com</a>,
 
 </span>
 <span class="date" title="Fri Jun 11 07:28:27 2010">Jun 11, 2010</span>
 <div>
<div class="commentcontent">
<p>Hello, I am using httplib2 to test a localhost server. I do the following: 1) first request with credentials to check that it works (and it works!) 2) second request (using the same object as before and clearing credentials to check that validation works fine), but I still receive 200 as feedback, meaning that the credentials are being sent.  Any clue will be appreciated. Thanks </p><p>Dan. </p>
</div>
 
 
 </div>
 </div>
 

 
 <div class="artifactcomment"
 
 >
 
 
 
 
 
 
 <span class="author">Comment
 
 by 
 
 <a style="white-space: nowrap" href="/u/105139429687485145174/">cyker...@gmail.com</a>,
 
 </span>
 <span class="date" title="Fri Jun 17 07:48:56 2011">Jun 17, 2011</span>
 <div>
<div class="commentcontent">
<p>Agree with bjourne. {&#x27;Content-type&#x27;: &#x27;application/x-www-form-urlencoded&#x27;} is not automatically set and should be manually set when POSTing. Otherwise, the POST is not successful. </p>
</div>
 
 
 </div>
 </div>
 

</div>
</div>

 


 <script type="text/javascript">
 function delComment(sequence_num, create_time, delete_mode) {
 var f = document.forms["delcom"];
 f.sequence_num.value = sequence_num;
 f.create_time.value = create_time;
 f.mode.value = delete_mode;
 f.submit();
 return false;
 }
 </script>


 </div>
 
 
 
 <form name="delcom" action="../w/delComment.do" method="POST">
 <input type="hidden" name="sequence_num" value="" >
 <input type="hidden" name="create_time" value="" >
 <input type="hidden" name="mode" value="" >
 <input type="hidden" name="pagename" value="Examples" >
 <input type="hidden" name="token" value="iElak6eun-HcxTQFldHga11rLTw:1325929438858" >
 </form>



 <script src="http://www.gstatic.com/codesite/ph/1847340689237817661/js/prettify/prettify.js"></script>
 <script type="text/javascript">
 prettyPrint();
 </script>

<script type="text/javascript" src="http://www.gstatic.com/codesite/ph/1847340689237817661/js/dit_scripts.js"></script>


<script type="text/javascript" src="https://apis.google.com/js/plusone.js">
</script>

  
 
 
 <script type="text/javascript" src="http://www.gstatic.com/codesite/ph/1847340689237817661/js/ph_core.js"></script>
 
 
 
 
 <script type="text/javascript" src="/js/codesite_product_dictionary_ph.pack.04102009.js"></script>
</div> 
<div id="footer" dir="ltr">
 <div class="text">
 &copy;2011 Google -
 <a href="/projecthosting/terms.html">Terms</a> -
 <a href="http://www.google.com/privacy.html">Privacy</a> -
 <a href="/p/support/">Project Hosting Help</a>
 </div>
</div>
 <div class="hostedBy" style="margin-top: -20px;">
 <span style="vertical-align: top;">Powered by <a href="http://code.google.com/projecthosting/">Google Project Hosting</a></span>
 </div>
 
 


 
 </body>
</html>


